<template>
  <div v-if="visible" class="share-overlay" @click="handleOverlayClick">
    <div class="share-box" @click.stop>
      <!-- 头部 -->
      <div class="share-header">
        <span class="share-title">分享至</span>
        <button class="close-btn" @click="close">
          <img src="@/assets/icons/close.png" alt="关闭" class="close-icon" />
        </button>
      </div>
      
      <!-- 分享选项 -->
      <div class="share-options">
        <div class="share-item" @click="handleWeChatShare">
          <div class="share-icon wechat-icon">
            <img src="@/assets/icons/weixin.png" alt="微信好友" class="share-icon-img" />
          </div>
          <span class="share-label">微信好友</span>
        </div>
        
        <div class="share-item" @click="handleGenerateImage">
          <div class="share-icon image-icon">
            <img src="@/assets/icons/image.png" alt="生成图片" class="share-icon-img" />
          </div>
          <span class="share-label">生成图片</span>
        </div>
        
        <div class="share-item" @click="handleCopyLink">
          <div class="share-icon link-icon">
            <img src="@/assets/icons/link.png" alt="复制链接" class="share-icon-img" />
          </div>
          <span class="share-label">复制链接</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
interface Props {
  visible: boolean
}

interface Emits {
  (e: 'update:visible', value: boolean): void
  (e: 'wechat-share'): void
  (e: 'generate-image'): void
  (e: 'copy-link'): void
}

defineProps<Props>()
const emit = defineEmits<Emits>()

const close = () => {
  emit('update:visible', false)
}

// 暴露 close 方法给父组件
defineExpose({
  close
})

const handleOverlayClick = () => {
  close()
}

const handleWeChatShare = () => {
  emit('wechat-share')
  close()
}

const handleGenerateImage = () => {
  emit('generate-image')
  close()
}

const handleCopyLink = () => {
  emit('copy-link')
  close()
}
</script>

<style scoped>
.share-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fadeIn 0.3s ease-out;
}

.share-box {
  background-color: white;
  width: 100%;
  max-width: 750px;
  border-radius: 16px 16px 0 0;
  padding: 0;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
  animation: slideUp 0.3s ease-out;
  transform-origin: bottom;
}

.share-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid #f0f0f0;
}

.share-title {
  font-size: 34px;
  font-weight: bold;
  color: #000;
}

.close-btn {
  background: none;
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.close-btn:hover {
  background-color: #f5f5f5;
}

.close-icon {
  width: 40px;
  height: 40px;
  object-fit: contain;
}

.share-options {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 0 !important;
  padding-bottom: 50px !important;
  margin: 0;
  gap: 80px;
}

.share-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  transition: transform 0.2s ease;
}

.share-icon {
  width: 100px;
  height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
  transition: transform 0.2s ease;
}

.share-icon-img {
  width: 100px;
  height: 100px;
  object-fit: contain;
}

.share-label {
  font-size: 26px;
  color: #000;
  text-align: center;
  font-weight: 500;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes slideUp {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}

/* 响应式设计 */
@media (max-width: 480px) {
  .share-options {
    padding: 24px 16px 32px;
    gap: 16px;
  }
  
  .share-icon {
    width: 80px;
    height: 80px;
  }
  
  .share-icon-img {
    width: 60px;
    height: 60px;
  }
  
  .share-label {
    font-size: 13px;
  }
  
  .share-header {
    padding: 16px 20px 12px;
  }
  
  .share-title {
    font-size: 16px;
  }
}
</style>
